import { Injectable } from '@nestjs/common';
import { CreatePreviewDto } from './dto/create-preview.dto';
import { UpdatePreviewDto } from './dto/update-preview.dto';
import * as fs from 'fs';
import * as path from 'path';
import * as pdf from 'pdf-parse';

@Injectable()
export class PreviewService {
  async readPdf(filePath: string): Promise<string> {
    const docxPath = path.resolve(process.cwd(), 'word', filePath);

    console.log(docxPath);


    const dataBuffer = fs.readFileSync(path.resolve(docxPath));
    const data = await pdf(dataBuffer);
    return data.text;
  }
  create(createPreviewDto: CreatePreviewDto) {
    return 'This action adds a new preview';
  }

  findAll() {
    return `This action returns all preview`;
  }

  findOne(id: number) {
    return `This action returns a #${id} preview`;
  }

  update(id: number, updatePreviewDto: UpdatePreviewDto) {
    return `This action updates a #${id} preview`;
  }

  remove(id: number) {
    return `This action removes a #${id} preview`;
  }
}
